﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Whatzup.Mobi.AppSvc;
using Whatzup.Mobi.Test.Moq;
using Whatzup.Mobi.AppSvc.Provider;
using Whatzup.Mobi.Common.Model;

namespace Whatzup.Mobi.Test
{
    [TestClass]
    public class MediaRepoTest
    {
        class Arrangement
        {
            public MoqServiceLocator moqServiceLocator;
            public Arrangement()
            {
                moqServiceLocator = new MoqServiceLocator();
            }

            public IMediaRepo CreateTarget()
            {
                return new MediaRepo(moqServiceLocator.Object);
            }
        }
        [TestMethod]
        [ExpectedException(typeof(ArgumentNullException))]
        public void Call_GetPcMediaUrl_InvalidUrl_Throws()
        {
            Arrangement a = new Arrangement();

            a.moqServiceLocator.moqProvider.retrievedData.Add(UrlType.pc, "PC Url");
            a.moqServiceLocator.moqProvider.retrievedData.Add(UrlType.mobile, "Mobile Url");

            IMediaRepo target = a.CreateTarget();

            try
            {
                CompositeMediaType actual = target.GetPcMediaUrl();
            }
            catch (Exception ex)
            {
                Assert.AreEqual("Value cannot be null.\r\nParameter name: Uri", ex.Message);
                throw;
            }
        }
        [TestMethod]
        [ExpectedException(typeof(ArgumentNullException))]
        public void Call_GetMobileUrl_InvalidUrl_Throws()
        {
            Arrangement a = new Arrangement();

            a.moqServiceLocator.moqProvider.retrievedData.Add(UrlType.pc, "PC Url");
            a.moqServiceLocator.moqProvider.retrievedData.Add(UrlType.mobile, "Mobile Url");

            IMediaRepo target = a.CreateTarget();

            try
            {
                CompositeMediaType actual = target.GetMobileUrl();
            }
            catch(Exception ex)
            {
                Assert.AreEqual("Value cannot be null.\r\nParameter name: Uri", ex.Message);
                throw;
            }
        }
        [TestMethod]
        public void Call_GetMobileUrl_ValidUrl_CorrectCompositeMediaType()
        {
            Arrangement a = new Arrangement();

            a.moqServiceLocator.moqProvider.retrievedData.Add(UrlType.pc, @"http://pc.com/");
            a.moqServiceLocator.moqProvider.retrievedData.Add(UrlType.mobile, @"http://mobile.com/");

            IMediaRepo target = a.CreateTarget();

            CompositeMediaType actual = target.GetMobileUrl();

            Assert.AreEqual(@"http://mobile.com/", actual.Url);
            Assert.AreEqual("acc", actual.FormatType);
        }
        [TestMethod]
        public void Call_GetPcMediaUrl_ValidUrl_CorrectCompositeMediaType()
        {
            Arrangement a = new Arrangement();

            a.moqServiceLocator.moqProvider.retrievedData.Add(UrlType.pc, @"http://pc.com/");
            a.moqServiceLocator.moqProvider.retrievedData.Add(UrlType.mobile, @"http://mobile.com/");

            IMediaRepo target = a.CreateTarget();

            CompositeMediaType actual = target.GetPcMediaUrl();

            Assert.AreEqual(@"http://pc.com/", actual.Url);
            Assert.AreEqual("pls", actual.FormatType);
        }
    }
}
